/**
 * @FileName: MyApplicationEnvironmentPreParedEventListener.java
 * @Package: com.springboot.listener
 * @author lig134
 * @created 2017/3/7 10:23
 * <p>
 * Copyright 2015 ziroom
 */
package com.springboot.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;

import java.util.Iterator;

/**
 * <p></p>
 *spring boot 配置环境事件监听
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *获取到ConfigurableEnvironment后可以对配置信息做操作
 * 例如：修改默认的配置，增加额外的配置信息等等。。。
 * @author lig134
 * @since 1.0
 * @version 1.0
 */
public class MyApplicationEnvironmentPreParedEventListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent>{
    Logger logger= LoggerFactory.getLogger(MyApplicationEnvironmentPreParedEventListener.class);
    @Override
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        ConfigurableEnvironment envi=event.getEnvironment();
        MutablePropertySources maps=envi.getPropertySources();
        if(maps!=null){
            Iterator<PropertySource<?>> iter=maps.iterator();
            while (iter.hasNext()){
                PropertySource<?> ps=iter.next();
                logger.info("配置信息为：ps.getName:{},ps.getSource:{},ps.getClass:{}",ps.getName(),ps.getSource(),ps.getClass());
            }

        }
    }
}